home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / fn-cache.h < prev    next >
C/C++ Source or Header  |  1996-10-26  |  3KB  |  129 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_fn_cache_h)
  24. #define octave_fn_cache_h 1
  25.  
  26. #include <ctime>
  27.  
  28. #include <string>
  29.  
  30. #include "Map.h"
  31.  
  32. class string_vector;
  33.  
  34. // XXX FIXME XXX -- this should maybe be nested in the
  35. // octave_fcn_file_name_cache class...
  36.  
  37. class
  38. file_name_cache_elt
  39. {
  40. public:
  41.  
  42.   file_name_cache_elt (void)
  43.     : timestamp (0), fcn_file_names (), fcn_file_names_no_suffix ()
  44.       { update (string ()); }
  45.  
  46.   file_name_cache_elt (const string& dir_name)
  47.     : timestamp (0), fcn_file_names (), fcn_file_names_no_suffix ()
  48.       { update (dir_name); }
  49.  
  50.   file_name_cache_elt (const file_name_cache_elt& elt)
  51.     {
  52.       timestamp = elt.timestamp;
  53.       fcn_file_names = elt.fcn_file_names;
  54.       fcn_file_names_no_suffix = elt.fcn_file_names_no_suffix;
  55.     }
  56.  
  57.   file_name_cache_elt& operator = (const file_name_cache_elt& elt)
  58.     {
  59.       if (&elt != this)
  60.     {
  61.       timestamp = elt.timestamp;
  62.       fcn_file_names = elt.fcn_file_names;
  63.       fcn_file_names_no_suffix = elt.fcn_file_names_no_suffix;
  64.     }
  65.       return *this;
  66.     }
  67.  
  68.   ~file_name_cache_elt (void) { }
  69.  
  70.   int length (void) { return fcn_file_names.length (); }
  71.  
  72.   bool update (const string& dir_name);
  73.  
  74.   // The time we last read this directory.
  75.   time_t timestamp;
  76.  
  77.   // The list of file names in this directory.
  78.   string_vector fcn_file_names;
  79.  
  80.   // The list of file names in this directory without the .m or .oct
  81.   // suffixes.
  82.   string_vector fcn_file_names_no_suffix;
  83. };
  84.  
  85. class
  86. octave_fcn_file_name_cache
  87. {
  88. protected:
  89.  
  90.   octave_fcn_file_name_cache (void)
  91.     : cache (file_name_cache_elt ())
  92.       { update (string ()); }
  93.  
  94. public:
  95.  
  96.   ~octave_fcn_file_name_cache (void) { }
  97.  
  98.   bool update (const string& path);
  99.  
  100.   static string_vector list (bool no_suffix = false)
  101.     { return list (string (), no_suffix); }
  102.  
  103.   static string_vector list (const string& path, bool no_suffix = false);
  104.  
  105.   static string_vector list_no_suffix (void)
  106.     { return list (true); }
  107.  
  108.   static string_vector list_no_suffix (const string& path)
  109.     { return list (path, true); }
  110.  
  111. private:
  112.  
  113.   static octave_fcn_file_name_cache* instance;
  114.  
  115.   // An associative array of all the directory names in the load path
  116.   // and the corresponding cache elements.
  117.   CHMap<file_name_cache_elt> cache;
  118.  
  119.   string_vector do_list (const string& path, bool no_suffix);
  120. };
  121.  
  122. #endif
  123.  
  124. /*
  125. ;;; Local Variables: ***
  126. ;;; mode: C++ ***
  127. ;;; End: ***
  128. */
  129.